//
//  PracticalView.m
//  MyProject
//
//  Created by dllo on 15/11/1.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "PracticalView.h"
#import "SmallPracticalCollectionCell.h"
#import "CanModel.h"
#import "SmallSecViewController.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height
@implementation PracticalView


- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
    
}


- (void)create{
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(110, 150);
    layout.minimumLineSpacing = 10;
    layout.minimumInteritemSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 110, 10);
    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:layout];
    [self addSubview:self.collection];
    self.collection.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.2];
    self.collection.dataSource = self;
    self.collection.delegate = self;
    [self.collection registerClass:[SmallPracticalCollectionCell class] forCellWithReuseIdentifier:@"reuse"];
    
}




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.array.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    SmallPracticalCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];


    cell.canModel = self.array[indexPath.row];
    cell.backgroundColor = [UIColor whiteColor];
  
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    SmallSecViewController *secVC = [[SmallSecViewController alloc] init];
    [self.VC.navigationController pushViewController:secVC animated:YES];
    secVC.model = self.array[indexPath.row];

    
}










@end
